%% Copyright 2008 Kevin A. Smith 
%% Licensed under the Apache License, Version 2.0 (the "License"); 
%% you may not use this file except in compliance with the License. 
%% You may obtain a copy of the License at 
%%
%% http://www.apache.org/licenses/LICENSE-2.0 
%%
%% Unless required by applicable law or agreed to in writing, software 
%% distributed under the License is distributed on an "AS IS" BASIS, 
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
%% See the License for the specific language governing permissions and 
%% limitations under the License.

-module(terminate_instance_parser).

-compile([export_all]).

callback({startElement, _, "item", _, _}, {_Current, _Flag, All}) ->
	{[], [], All};
callback({startElement, _, "instanceId", _, _}, {Current, _Flag, All}) ->
	{Current, instanceId, All};
callback({endElement, _, "item", _}, {Current, _Flag, All}) ->
	{[], [], lists:append(All, [Current])};
callback({startElement, _, "shutdownState", _, _}, {Current, _Flag, All}) ->
	{Current, shutdownState, All};
callback({endElement, _, "shutdownState", _}, {Current, _Flag, All}) ->
	{Current, [], All};
callback({startElement, _, "previousState", _, _}, {Current, _Flag, All}) ->
	{Current, previousState, All};
callback({endElement, _, "previousState", _}, {Current, _Flag, All}) ->
	{Current, [], All};	
callback({startElement, _, "code", _, _}, {Current, shutdownState, All}) ->
	{Current, shutdownStateCode, All};
callback({endElement, _, "code", _}, {Current, shutdownStateCode, All}) ->
	{Current, shutdownState, All};
callback({endElement, _, "code", _}, {Current, previousStateCode, All}) ->
	{Current, previousState, All};
callback({startElement, _, "code", _, _}, {Current, previousState, All}) ->
	{Current, previousStateCode, All};
callback({startElement, _, "name", _, _}, {Current, shutdownState, All}) ->
	{Current, shutdownStateName, All};
callback({startElement, _, "name", _, _}, {Current, previousState, All}) ->
	{Current, previousStateName, All};
callback(endDocument, {_Current, _Flag, All}) ->
	{ok, All};		
callback({characters, Text}, {Current, Flag, All}) when is_tuple(Flag) ->
	{Name, Buf} = Flag,
	Buf1 = lists:append(Buf, Text),
	{Current, {Name, Buf1}, All};
callback({characters, Text}, {Current, Flag, All}) when is_atom(Flag) ->
    Current1 = lists:append(Current, [{Flag, Text}]),
    {Current1, Flag, All};
callback(_Event, State) ->
    State.	